import { createRouter, createWebHashHistory } from "vue-router";
import { lazyComponents } from "./routerUtils";
import { showFullLoading, hideFullLoading } from "@/utils/nprogress";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    { path: "/", redirect: "/index" },
    { path: "/index", component: lazyComponents("/Index") },
    { path: "/refComp", component: lazyComponents("/FunctionComp/RefComp") },
    { path: "/propsComp", component: lazyComponents("/FunctionComp/PropsComp") },
    { path: "/compLife", component: lazyComponents("/FunctionComp/CompLife") },
    { path: "/computedComp", component: lazyComponents("/FunctionComp/ComputedComp") },
    { path: "/watchComp", component: lazyComponents("/FunctionComp/WatchComp") },
    { path: "/routerComp", component: lazyComponents("/FunctionComp/RouterComp") },
    {
      path: "/routerCompTest",
      component: lazyComponents("/FunctionComp/RouterComp/RouterCompTest.vue"),
    },
    { path: "/storeComp", component: lazyComponents("/FunctionComp/StoreComp") },
    { path: "/eventComp", component: lazyComponents("/FunctionComp/EventComp") },
    { path: "/keepAliveComp", component: lazyComponents("/FunctionComp/KeepAliveComp") },
    { path: "/dynamicComp", component: lazyComponents("/FunctionComp/DynamicComp") },
    { path: "/dynamicImgComp", component: lazyComponents("/FunctionComp/DynamicImgComp") },
    { path: "/provideComp", component: lazyComponents("/FunctionComp/ProvideComp") },
    { path: "/renderComp", component: lazyComponents("/FunctionComp/RenderComp") },
    { path: "/changeThemeColor", component: lazyComponents("/ExtendComp/ChangeThemeColor") },
    { path: "/skeletonComp", component: lazyComponents("/ExtendComp/SkeletonComp") },
    { path: "/chatGTPDemo", component: lazyComponents("/ExtendComp/ChatGTPDemo") },
    { path: "/chartComp", component: lazyComponents("/ExtendComp/ChartComp") },
    { path: "/testTable", component: lazyComponents("/TestTable") },
  ],
});

router.beforeEach((to, from, next) => {
  showFullLoading();
  next();
});

router.afterEach((to, from) => {
  hideFullLoading();
});
export default router;
